package com.example.demo.core.common.resp;

import com.example.demo.core.common.costant.ErrorCodeEnum;

import lombok.Getter;

@Getter
public class RestResp<T> {
    private String code;
    private String message;
    private T data;

    public RestResp() {
        this.code = ErrorCodeEnum.SUCCESS.getCode();
        this.message = ErrorCodeEnum.SUCCESS.getMessage();
    }

    public RestResp(ErrorCodeEnum errorCodeEnum) {
        this.code = errorCodeEnum.getCode();
        this.message = errorCodeEnum.getMessage();
    }

    public RestResp(T data) {
        this();
        this.data = data;
    }

    public static <T> RestResp<T> success(T data) {
        return new RestResp<>(data);
    }

    public static RestResp<Void> success() {
        return new RestResp<>();
    }

    public static RestResp<Void> fail(ErrorCodeEnum errorCodeEnum) {
        return new RestResp<>(errorCodeEnum);
    }
}
